package com.qqs.distributed.advice;

import com.qqs.distributed.annotation.CacheType;
import com.qqs.distributed.annotation.LockType;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class CacheAttribute {
    private CacheType cacheType;
    private LockType lockType;
    private String cacheKeyExpr;
    private String bloom;
    private long ttl;
    private TimeUnit timeUnit;
    private long lockTtl;
    private TimeUnit lockTimeUnit;
    private Method method;
    private Type returnType;

    public CacheAttribute() {
    }

    public CacheAttribute(CacheType cacheType, LockType lockType, String cacheKeyExpr, String bloom, long ttl, TimeUnit timeUnit, long lockTtl, TimeUnit lockTimeUnit, Method method, Type returnType) {
        this.cacheType = cacheType;
        this.lockType = lockType;
        this.cacheKeyExpr = cacheKeyExpr;
        this.bloom = bloom;
        this.ttl = ttl;
        this.timeUnit = timeUnit;
        this.lockTtl = lockTtl;
        this.lockTimeUnit = lockTimeUnit;
        this.method = method;
        this.returnType = returnType;
    }

    public Type getReturnType() {
        return returnType;
    }

    public void setReturnType(Type returnType) {
        this.returnType = returnType;
    }

    public LockType getLockType() {
        return lockType;
    }

    public void setLockType(LockType lockType) {
        this.lockType = lockType;
    }

    public Method getMethod() {
        return method;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public CacheType getCacheType() {
        return cacheType;
    }

    public void setCacheType(CacheType cacheType) {
        this.cacheType = cacheType;
    }


    public String getCacheKeyExpr() {
        return cacheKeyExpr;
    }

    public void setCacheKeyExpr(String cacheKeyExpr) {
        this.cacheKeyExpr = cacheKeyExpr;
    }

    public long getTtl() {
        return ttl;
    }

    public void setTtl(long ttl) {
        this.ttl = ttl;
    }

    public TimeUnit getTimeUnit() {
        return timeUnit;
    }

    public void setTimeUnit(TimeUnit timeUnit) {
        this.timeUnit = timeUnit;
    }

    public long getLockTtl() {
        return lockTtl;
    }

    public void setLockTtl(long lockTtl) {
        this.lockTtl = lockTtl;
    }

    public TimeUnit getLockTimeUnit() {
        return lockTimeUnit;
    }

    public void setLockTimeUnit(TimeUnit lockTimeUnit) {
        this.lockTimeUnit = lockTimeUnit;
    }

    public String getBloom() {
        return bloom;
    }

    public void setBloom(String bloom) {
        this.bloom = bloom;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CacheAttribute that = (CacheAttribute) o;
        return ttl == that.ttl && lockTtl == that.lockTtl && cacheType == that.cacheType && lockType == that.lockType && Objects.equals(cacheKeyExpr, that.cacheKeyExpr) && Objects.equals(bloom, that.bloom) && timeUnit == that.timeUnit && lockTimeUnit == that.lockTimeUnit && Objects.equals(method, that.method) && Objects.equals(returnType, that.returnType);
    }

    @Override
    public int hashCode() {
        return Objects.hash(cacheType, lockType, cacheKeyExpr, bloom, ttl, timeUnit, lockTtl, lockTimeUnit, method, returnType);
    }

    @Override
    public String toString() {
        return "CacheAttribute{" +
                "cacheType=" + cacheType +
                ", lockType=" + lockType +
                ", cacheKeyExpr='" + cacheKeyExpr + '\'' +
                ", bloom='" + bloom + '\'' +
                ", ttl=" + ttl +
                ", timeUnit=" + timeUnit +
                ", lockTtl=" + lockTtl +
                ", lockTimeUnit=" + lockTimeUnit +
                ", method=" + method +
                ", returnType=" + returnType +
                '}';
    }
}
